<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\model;

use think\Model;

/**
 * 用户观看视频时常 模型
 * @package app\user_center\model
 */
class VideoPlayWatchcount extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_video_play_watchcount';
	
	public function getWatchSecondsByid($uid, $play_id){
		$map = [];
		$map['uid'] 	= $uid;
		$map['play_id'] = $play_id;
		$res = $this -> where($map) -> whereTime('create_time', 'today') -> find();
		
		if($res){
            return array_out(200, 'success', $res);
        }else{
            return array_out(-1001, 'error');
        }
	}
	
    /**
     * 添加数据
     * @param int $uid 用户id
     * @param int $play_id 视频id
     * @param int $seconds 观看时间
     * @param int $duration 原视频时长
     * @author shiqiang
     * @return bool
     */
    public function addData($uid, $play_id, $seconds, $duration){
        $data['uid']            = $uid;
        $data['play_id']      	= $play_id;
        $data['seconds']      	= $seconds;
        $data['duration']      	= $duration;
        $res = $this -> isUpdate(false) -> data($data, true) -> save();

        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	public function editData($wath_id, $seconds){
		$data['seconds'] = $seconds;
		$res = $this -> where('id', $wath_id) -> update($data);
		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
}
